home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / src / agg / Set_scp.c < prev    next >
C/C++ Source or Header  |  1992-01-23  |  14KB  |  377 lines

  1. #line 1 "/fzi/prost/stone/SOS3-2/src/agg/Set.c"
  2. /* --------------------------------------------------------------------------
  3.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  4.  *
  5.  * You can use and distribute this software under the terms of the licence
  6.  * you should have received along with this program.
  7.  * If not or if you want additional information, write to
  8.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  9.  * D-7500 Karlsruhe 1, Germany.
  10.  * --------------------------------------------------------------------------
  11.  */
  12. // **************************************************************************
  13. // Module Set                       03/07/89           Bernhard Schiefer (bs)
  14. //                                                     modified: 23/7/90 (ja)
  15. //                                                              24/10/91 (bs)
  16. // **************************************************************************
  17. // implements methods of classes: Set
  18. // **************************************************************************
  19.  
  20. #include "agg_err.h"
  21. #include "trc_agg.h"
  22. #include "sys.h"
  23.  
  24. #include "agg_sos.h"
  25.  
  26. // *** Sets are based on Object_sos_Bool_Mappings ***
  27.  
  28. // **************************************************************************
  29. void _sos_Object_Set::local_initialize (sos_Object_Set set)
  30. // **************************************************************************
  31. {  T_PROC ("sos_Object_Set::local_initialize");
  32.    TT (agg_H, T_ENTER);
  33.  
  34.    set.set_m (sos_Object_sos_Bool_Mapping::create
  35.          (set.container(),
  36.           set.get_list_cursor(),
  37.           set.get_based_on_equal()));
  38.  
  39.    TT (agg_H, T_LEAVE);
  40. } // ** local_initialize **
  41.  
  42. // **************************************************************************
  43. void _sos_Object_Set::local_finalize (sos_Object_Set set)
  44. // **************************************************************************
  45. {  T_PROC ("sos_Object_Set::local_finalize");
  46.    TT (agg_H, T_ENTER);
  47.  
  48.    set.get_m().destroy();
  49.  
  50.    TT (agg_H, T_LEAVE);
  51. } // ** local_finalize **
  52.  
  53. // **************************************************************************
  54. void _sos_Object_Set::insert (sos_Typed_id &_tpid,sos_Object o)
  55. // **************************************************************************
  56. // fuege das Objekt o in das Set ein, es wird die Anzahl der danach im
  57. // Set vorhandenen Exemplare geliefert.
  58. {
  59.    T_PROC ("sos_Object_Set::insert");
  60.    TT (agg_H, T_ENTER);
  61.  
  62.    sos_Object_sos_Bool_Mapping m = sos_Object_Set::make(_tpid,this).get_m();
  63.    m.insert (o, TRUE);
  64.  
  65.    TT (agg_H, T_LEAVE);
  66. } // ** insert **
  67.  
  68. // **************************************************************************
  69. void _sos_Object_Set::remove (sos_Typed_id &_tpid,sos_Object o)
  70. // **************************************************************************
  71. // loesche ein Objekt o, es wird TRUE,geliefert, falls es drin war
  72. {  
  73.    T_PROC ("sos_Object_Set::remove");
  74.    TT (agg_H, T_ENTER);
  75.  
  76.    sos_Object_Set::make(_tpid,this).get_m().remove (o);
  77.  
  78.    TT (agg_H, T_LEAVE);
  79. } // ** remove **
  80.  
  81. // **************************************************************************
  82. void _sos_Object_Set::__plus_assign (sos_Typed_id &_tpid,sos_Object_Set aset)
  83. // **************************************************************************
  84. // Nach A += B wurden alle Elemente in B zu A aufaddiert
  85. {
  86.    T_PROC ("sos_Object_Set::operator+=");
  87.    TT (agg_H, T_ENTER);
  88.  
  89.    sos_Object_sos_Bool_Mapping this_m = sos_Object_Set::make(_tpid,this).get_m();
  90.    sos_Object_sos_Bool_Mapping aset_m = aset.get_m();
  91.  
  92.    sos_Cursor cur = aset_m.open_cursor ();
  93.    for (;aset_m.is_valid (cur); aset_m.to_succ (cur))
  94.    {  sos_Object o = aset_m.get_key (cur);
  95.       this_m.insert (o, TRUE);
  96.    } // for
  97.    aset_m.close_cursor (cur);
  98.  
  99.    TT (agg_H, T_LEAVE);
  100. } // ** operator+= **
  101.  
  102. // **************************************************************************
  103. void _sos_Object_Set::__minus_assign (sos_Typed_id &_tpid,sos_Object_Set aset)
  104. // **************************************************************************
  105. // Nach A -= B wurden aus A alle Elemente, die in B sind, entfernt
  106. {  
  107.    T_PROC ("sos_Object_Set::operator-=");
  108.    TT (agg_H, T_ENTER);
  109.  
  110.    sos_Object_sos_Bool_Mapping this_m = sos_Object_Set::make(_tpid,this).get_m();
  111.    sos_Object_sos_Bool_Mapping aset_m = aset.get_m();
  112.  
  113.    sos_Cursor cur = aset_m.open_cursor();
  114.    for (;aset_m.is_valid (cur);aset_m.to_succ (cur))
  115.    {  sos_Object o = aset_m.get_key (cur);
  116.       this_m.remove (o);
  117.    } // for
  118.    aset_m.close_cursor (cur);
  119.  
  120.    TT (agg_H, T_LEAVE);
  121. } // ** operator-= **
  122.  
  123. // **************************************************************************
  124. void _sos_Object_Set::__times_assign (sos_Typed_id &_tpid,sos_Object_Set aset)
  125. // **************************************************************************
  126. // Liefert die Schnittmenge von A und B in A,
  127. // Also entferne aus self alle Elemente, die nicht in aset sind
  128. {
  129.    T_PROC ("sos_Object_Set::operator*=");
  130.    TT (agg_H, T_ENTER);
  131.  
  132.    sos_Object_sos_Bool_Mapping aset_m = aset.get_m();
  133.    sos_Object_sos_Bool_Mapping this_m = sos_Object_Set::make(_tpid,this).get_m();
  134.  
  135.    sos_Cursor cur = this_m.open_cursor();
  136.    for (;this_m.is_valid (cur);)
  137.    {  sos_Object o = this_m.get_key (cur);
  138.       if (NOT aset_m.is_key (o))
  139.          this_m.remove_at (cur);
  140.       else
  141.          this_m.to_succ (cur);
  142.    } // for 
  143.    this_m.close_cursor (cur);
  144.  
  145.    TT (agg_H, T_LEAVE);
  146. } // ** operator*= **
  147.  
  148. // **************************************************************************
  149. sos_Bool _sos_Object_Set::__less (sos_Typed_id &_tpid,sos_Object_Set aset)
  150. // **************************************************************************
  151. // Liefert TRUE zurueck, wenn jedes Element aus this auch in aset ist
  152. // und aset mindestens ein Element mehr enthaelt
  153.    T_PROC ("sos_Object_Set::operator<");
  154.    TT (agg_H, T_ENTER);
  155.  
  156.    sos_Object_sos_Bool_Mapping aset_m = aset.get_m();
  157.    sos_Object_sos_Bool_Mapping this_m = sos_Object_Set::make(_tpid,this).get_m();
  158.    sos_Bool result = TRUE;
  159.  
  160.    if (this_m.card() >= aset_m.card())
  161.       result = FALSE;
  162.    else
  163.    {  sos_Cursor cur = this_m.open_cursor();
  164.       for (;this_m.is_valid (cur);this_m.to_succ (cur))
  165.       {  sos_Object o = this_m.get_key (cur);
  166.          if (NOT aset_m.is_key (o))
  167.          {  result = FALSE;
  168.             break;
  169.          }
  170.       } // for
  171.       this_m.close_cursor (cur);
  172.    }
  173.  
  174.    TT (agg_H, T_LEAVE);
  175.    return result;
  176. } // ** operator< **
  177.  
  178. // **************************************************************************
  179. sos_Bool _sos_Object_Set::__less_equal (sos_Typed_id &_tpid,sos_Object_Set aset)
  180. // **************************************************************************
  181. // Liefert TRUE zurueck, wenn jedes Element aus this auch in aset ist
  182.    T_PROC ("sos_Object_Set::operator<=");
  183.    TT (agg_H, T_ENTER);
  184.  
  185.    sos_Object_sos_Bool_Mapping aset_m = aset.get_m();
  186.    sos_Object_sos_Bool_Mapping this_m = sos_Object_Set::make(_tpid,this).get_m();
  187.    sos_Bool result = TRUE;
  188.  
  189.    // pruefe zuerst, ob die Anzahl der Elemente schon ein Ergebnis liefert
  190.    if (this_m.card() > aset_m.card())
  191.       result = FALSE;
  192.    else
  193.    {  sos_Cursor cur = this_m.open_cursor();
  194.       for (;this_m.is_valid (cur); this_m.to_succ (cur))
  195.       {  sos_Object o = this_m.get_key (cur);
  196.          if (NOT aset_m.is_key (o))
  197.          {  result = FALSE;
  198.             break;
  199.          }
  200.       } // for
  201.       this_m.close_cursor (cur);
  202.    }
  203.    TT (agg_H, T_LEAVE);
  204.    return result;
  205. } // ** operator<= **
  206.  
  207. // **************************************************************************
  208. sos_Bool _sos_Object_Set::__greater (sos_Typed_id &_tpid,sos_Object_Set aset)
  209. { return sos_Bool (aset < sos_Object_Set::make(_tpid,this)); }
  210. // **************************************************************************
  211.  
  212. // **************************************************************************
  213. sos_Bool _sos_Object_Set::__greater_equal (sos_Typed_id &_tpid,sos_Object_Set aset)
  214. { return sos_Bool (aset <= sos_Object_Set::make(_tpid,this)); }
  215. // **************************************************************************
  216.  
  217. // **************************************************************************
  218. void _sos_Object_Set::local_assign (sos_Object_Set x, sos_Object o)
  219. // **************************************************************************
  220. {  T_PROC ("sos_Object_Set::local_assign");
  221.    TT(agg_H, T_ENTER);
  222.  
  223.    sos_Object_Set y = sos_Object_Set::make (o);
  224.    x.get_m().assign (y.get_m());
  225.  
  226.    TT(agg_H, T_LEAVE);
  227. } // local_assign
  228.  
  229. // **************************************************************************
  230. sos_Bool _sos_Object_Set::local_equal (sos_Object_Set x,
  231.                       sos_Object     o,
  232.                        sos_Eq_kind    eq_kind)
  233. // **************************************************************************
  234. {  T_PROC ("sos_Object_Set::local_equal");
  235.    TT(agg_H, T_ENTER);
  236.    
  237.    sos_Bool result;
  238.  
  239.    if ((eq_kind EQ EQ_STRONG AND NOT o.has_type (x.type())) OR
  240.        (eq_kind EQ EQ_WEAK   AND NOT o.isa      (x.type())))
  241.       result = FALSE;
  242.    else
  243.    {  sos_Object_Set y = sos_Object_Set::make (o);
  244.       result = x.get_m().equal (y.get_m(), eq_kind);
  245.    }
  246.  
  247.    TT(agg_H, T_LEAVE);
  248.    return result;
  249. } // local_equal
  250.  
  251. // **************************************************************************
  252. sos_Int _sos_Object_Set::local_hash_value (sos_Object_Set x)
  253. // **************************************************************************
  254. {  T_PROC ("sos_Object_Set::local_hash_value");
  255.    TT(agg_H, T_ENTER);
  256.    
  257.    sos_Int result = x.get_m().hash_value ();
  258.  
  259.    TT(agg_H, T_LEAVE);
  260.  
  261.    return result;
  262. } // local_hash_value
  263.  
  264. // **************************************************************************
  265. sos_Bool _sos_Object_Set::is_element (sos_Typed_id &_tpid,sos_Object o)
  266. // **************************************************************************
  267. {  T_PROC ("sos_Object_Set::is_element");
  268.    TT (agg_H, T_ENTER);
  269.  
  270.    sos_Bool result = sos_Object_Set::make(_tpid,this).get_m().is_key (o);
  271.  
  272.    TT (agg_H, T_LEAVE);
  273.    return result;
  274. } // ** is_element(sos_Object)
  275.  
  276. // **************************************************************************
  277. sos_Object _sos_Object_Set::get (sos_Typed_id &_tpid,sos_Cursor c)
  278. // **************************************************************************
  279. {  T_PROC ("sos_Object_Set::get");
  280.    TT (agg_H, T_ENTER);
  281.  
  282.    sos_Object o = sos_Object_Set::make(_tpid,this).get_m().get_key (c);
  283.  
  284.    TT (agg_H, T_LEAVE);
  285.    return o;
  286. } // ** get **
  287.  
  288. // **************************************************************************
  289. void _sos_Object_Set::remove_at (sos_Typed_id &_tpid,sos_Cursor c)
  290. // **************************************************************************
  291. {  T_PROC ("sos_Object_Set::remove_at");
  292.    TT (agg_H, T_ENTER);
  293.  
  294.    sos_Object_Set::make(_tpid,this).get_m().remove_at (c);
  295.  
  296.    TT (agg_H, T_LEAVE);
  297. } // ** remove_at **
  298.  
  299. // **************************************************************************
  300. void _sos_Object_Set::clear(sos_Typed_id &_tpid)
  301. // **************************************************************************
  302. {  T_PROC ("sos_Object_Set::clear");
  303.    TT (agg_H, T_ENTER);
  304.    
  305.    sos_Object_Set::make(_tpid,this).get_m().clear();
  306.  
  307.    TT (agg_H, T_LEAVE);
  308. } // ** clear
  309.  
  310. // **************************************************************************
  311. sos_Int _sos_Object_Set::card (sos_Typed_id &_tpid)
  312. // **************************************************************************
  313. {  return sos_Object_Set::make(_tpid,this).get_m().card ();
  314. } // card
  315.  
  316. // **************************************************************************
  317. sos_Cursor _sos_Object_Set::open_cursor (sos_Typed_id &_tpid,sos_Container Cursor_ct)
  318. // **************************************************************************
  319. {  return sos_Object_Set::make(_tpid,this).get_m().open_cursor (Cursor_ct);
  320. } // open_cursor
  321.  
  322. // **************************************************************************
  323. void _sos_Object_Set::close_cursor (sos_Typed_id &_tpid,sos_Cursor c)
  324. // **************************************************************************
  325. {  sos_Object_Set::make(_tpid,this).get_m().close_cursor (c);
  326. } // close_cursor
  327.  
  328. // **************************************************************************
  329. sos_Cursor _sos_Object_Set::duplicate (sos_Typed_id &_tpid,sos_Cursor c)
  330. // **************************************************************************
  331. {  return sos_Object_Set::make(_tpid,this).get_m().duplicate (c);
  332. } // duplicate
  333.  
  334. // **************************************************************************
  335. sos_Bool _sos_Object_Set::is_valid (sos_Typed_id &_tpid,sos_Cursor c)
  336. // **************************************************************************
  337. {  return sos_Object_Set::make(_tpid,this).get_m().is_valid (c);
  338. } // ** is_valid **
  339.  
  340. // **************************************************************************
  341. sos_Bool _sos_Object_Set::to_first (sos_Typed_id &_tpid,sos_Cursor c)
  342. // **************************************************************************
  343. {  return sos_Object_Set::make(_tpid,this).get_m().to_first (c);
  344. } // to_first
  345.  
  346. // **************************************************************************
  347. sos_Bool _sos_Object_Set::to_last (sos_Typed_id &_tpid,sos_Cursor c)
  348. // **************************************************************************
  349. {  return sos_Object_Set::make(_tpid,this).get_m().to_last (c);
  350. } // to_last
  351.  
  352. // **************************************************************************
  353. sos_Bool _sos_Object_Set::to_succ (sos_Typed_id &_tpid,sos_Cursor c, sos_Int steps)
  354. // **************************************************************************
  355. {  T_PROC ("sos_Object_Set::to_succ");
  356.    TT (agg_H, T_ENTER);
  357.  
  358.    sos_Bool result = sos_Object_Set::make(_tpid,this).get_m().to_succ (c, steps);
  359.  
  360.    TT (agg_H, T_LEAVE);
  361.    return result;
  362. } // ** to_succ**
  363.  
  364. // **************************************************************************
  365. sos_Bool _sos_Object_Set::to_pred (sos_Typed_id &_tpid,sos_Cursor c, sos_Int steps)
  366. // **************************************************************************
  367. {  T_PROC ("sos_Object_Set::to_pred");
  368.    TT (agg_H, T_ENTER);
  369.  
  370.    sos_Bool result = sos_Object_Set::make(_tpid,this).get_m().to_pred (c, steps);
  371.    
  372.    TT (agg_H, T_LEAVE);
  373.    return result;
  374. } // ** to_pred **
  375.